/*
 * @lc app=leetcode.cn id=205 lang=cpp
 *
 * [205] 同构字符串
 */

#include <limits.h>

#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;

// @lc code=start
class Solution {
   public:
    bool isIsomorphic(string s, string t) {
        bool result = true;
        map<char, char> mapper1;
        map<char, char> mapper2;

        for (int i = 0; i < s.length(); i++) {
            if (mapper1.count(s[i]) == 0) {
                // 如果映射表中没有该元素，则新增映射关系
                mapper1.insert(pair<char, char>(s[i], t[i]));
            } else {
                // 如果已有该元素的映射关系，则判断映射是否正确
                if (mapper1[s[i]] != t[i]) {
                    result = false;
                    break;
                }
            }

            if (mapper2.count(t[i]) == 0) {
                mapper2.insert(pair<char, char>(t[i], s[i]));
            } else {
                if (mapper2[t[i]] != s[i]) {
                    result = false;
                    break;
                }
            }
        }

        return result;
    }
};
// @lc code=end
